package com.lcredu.seckill.controller;

import com.lcredu.seckill.service.UserService;
import com.lcredu.seckill.util.response.RespBean;
import com.lcredu.seckill.vo.LoginVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author 黎长容
 * @date 2025-08-24 14:57
 */
@Controller
@Slf4j
@RequestMapping("/login")
public class loginController {
    @Resource
    private UserService userService;

    //先测试跳转功能
    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }

    @PostMapping("/doLogin")
    @ResponseBody
    public RespBean doLogin(@Validated LoginVo loginVo, HttpServletRequest request, HttpServletResponse response) {
        System.out.println("hello");
        log.info("接收到的loginVo={}", loginVo);
        return userService.doLogin(loginVo, request, response);
    }
}
